import sys
from PyQt5.QtWidgets import QApplication, QWidget,QPushButton,QHBoxLayout,QRadioButton,QButtonGroup
from PyQt5.QtCore import pyqtSlot

def on_button_toggle(btn:QRadioButton):
    print(btn.text(),btn.isChecked())
#------------------------------------------------------
def init_widget(w:QWidget):
    # 设置窗口标题
    w.setWindowTitle("布局")
    # w.resize(640, 480)
    
    #创建布局
    layout = QHBoxLayout()
    #给Widget根容器设置布局方式
    w.setLayout(layout)
    
    btn1 = QRadioButton("男")
    btn2 = QRadioButton("女")
    btn3 = QRadioButton("妖")
    btn3.setChecked(True)
    
    group = QButtonGroup(w)
    group.addButton(btn1)
    group.addButton(btn2)#装在一个组里
    group.addButton(btn3)
    group.buttonToggled.connect(on_button_toggle)  
    
    layout.addWidget(btn1)
    layout.addWidget(btn2)
    layout.addWidget(btn3)

    
   
    
if __name__ == "__main__":
    # 1.创建应用程序
    app = QApplication(sys.argv)
    # 2.创建窗口
    w = QWidget()
    init_widget(w)
    # 3显示窗口
    w.show()
    # 4.等待窗口停止运行
    sys.exit(app.exec_())
